from scrapy.spider import Spider
from scrapy.selector import Selector

from spider.items import SpiderItem


class BitcitySpider(Spider):

    name = 'bitcity'
    start_urls = ["http://city.bitauto.com/"]

    def parse(self,response):

        sel = Selector(response)
        areas = sel.xpath('//div[@class="zimucity"]//dl')
        items = [] 
        for area in areas:

            item = SpiderItem()

            item["city"] = area.xpath('.//dd//li//a/text()').extract()
            item["cityurl"] = area.xpath('.//dd//li//a/@href').extract()
            item["type"] = "bitcity" 
            items.append(item)
        return items
